package br.com.werp.regras.almoxarifado.visao.decorador;

import br.com.werp.regras.geral.helpers.SetorHelper;
import br.com.werp.regras.geral.helpers.UsuarioHelper;
import br.com.werp.regras.geral.util.Constantes;
import br.com.werp.regras.geral.util.FormatDate;
import br.com.werp.regras.geral.util.Html;
import br.com.werp.regras.geral.vos.tabelas.Saida;
import br.com.werp.regras.geral.vos.tabelas.Setor;

import org.displaytag.decorator.TableDecorator;

import java.util.HashMap;
import java.util.Map;


/**
 * @author Sobreira
 * Criado em 04/11/2005
 */
public class SaidaPesquisa extends TableDecorator {
    public String getSaid_setor() throws Exception {
        Saida saida = (Saida) getCurrentRowObject();

        Map map = new HashMap();
        map.put("carregar_action", "");
        map.put("said_num", new Integer(saida.getSaid_num()));

        return Html.href("../movimentacao/AtenderSaidaForm.do", map) +
        SetorHelper.obterSetorPorId(SetorHelper.obterSetorEmpresa(
                saida.getSaid_setor()).getStem_setor()).getStor_descricao() +
        "</a>";
    }

    public String getSaid_data() {
        Saida saida = (Saida) getCurrentRowObject();

        String data =
            FormatDate.format(saida.getSaid_data(), Constantes.DATA_FORMATO);

        return Html.center(data);
    }

    public String getPrem_produto() throws Exception {
        Saida saida = (Saida) getCurrentRowObject();

        return "";
    }

    public String getRequisitor() throws Exception {
        Saida saida = (Saida) getCurrentRowObject();

        return UsuarioHelper.obterUsuario(saida.getSaid_requisitor())
                            .getUsur_nome();
    }

    public String getSaid_status() throws Exception {
        Saida saida = (Saida) getCurrentRowObject();

        if ("A".equals(saida.getSaid_status())) {
            return "ATENDIDA";
        } else if ("C".equals(saida.getSaid_status())) {
            return "CANCELADA";
        } else if ("P".equals(saida.getSaid_status())) {
            return "PENDENTE";
        }

        return null;
    }
}
